home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3726 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. Path: dawn.mmm.com!news
  2. From: kjhopps@mmm.com (Kevin J Hopps)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Strongly Typed Function Pointers
  5. Date: 25 Jan 1996 14:41:33 GMT
  6. Organization: 3M - St. Paul, MN  55144-1000 US
  7. Message-ID: <4e84qt$74u@dawn.mmm.com>
  8. References: <erik-2401961956090001@annex-dialup02.med.cornell.edu>
  9. Reply-To: kjhopps@mmm.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Erik A. Dahl (erik@mail.med.cornell.edu) wrote:
  13. > I have a program that I'm porting from C to C++ which uses void (*)(void*)
  14. > function pointers to call many differant "types" of functions (ones with
  15. > differant argument lists).  This of course works in C but I'm dying in C++
  16. > with compiler errors (becuase the pointer isn't of the right type).  Is
  17. > there an easy way around this problem??
  18.  
  19. You might be able to get away with casting the function pointer to a
  20. different type of function pointer and calling throught the result.  But
  21. this is not guaranteed to work.  From the April working paper:
  22.     A pointer to a function can be explicitly converted to a pointer to a
  23.     function of a different type. The effect of calling a function
  24.     through a pointer to a function type that differs from the type used
  25.     in the definition of the function is undefined. Except that convert-
  26.     ing an rvalue of type "pointer to T1" to the type "pointer to T2"
  27.     (where T1 and T2 are function types) and back to its original type
  28.     yields the original pointer value, the result of such a pointer con-
  29.     version is unspecified.
  30. --
  31. Kevin J. Hopps                  e-mail: kjhopps@mmm.com
  32. 3M Company                      phone:  (612) 737-4643
  33. 3M Center, Bldg. 235-2D-57      fax:    (612) 737-2700
  34. St. Paul, MN 55144-1000         Opinions are my own.  I don't speak for 3M.
  35.     But 3M speaks for me -- I did not write the following line:
  36.  
  37. Opinions expressed herein are my own and may not represent those of 3M.
  38.